package com.ssy.jt808.gateway.domain.converter;

import com.ssy.jt808.gateway.infrastructure.constant.Jt808Constant;
import com.ssy.jt808.gateway.sdk.terminal.constant.location.addition.DsmAlarmEnum;
import com.ssy.jt808.gateway.sdk.terminal.pojo.info.alarm.AlarmIdentificationInfo;
import com.ssy.jt808.gateway.sdk.terminal.pojo.info.alarm.DsmAlarmInfo;
import com.ssy.jt808.protocol.commons.transform.attribute.AlarmDSM;

/**
 * @author wangzezhou
 */
public class DsmAlarmInfoConverter{

  public static DsmAlarmInfo convertDsmAlarmInfo( AlarmDSM alarm ){

    DsmAlarmEnum type = DsmAlarmEnum.type(alarm.getType());

    DsmAlarmInfo dsmAlarmInfo = new DsmAlarmInfo();
    dsmAlarmInfo.setId(alarm.getId());
    dsmAlarmInfo.setState(alarm.getState());
    dsmAlarmInfo.setType(type);
    dsmAlarmInfo.setLevel(alarm.getLevel());
    dsmAlarmInfo.setAltitude(alarm.getAltitude());
    dsmAlarmInfo.setLat((float)(alarm.getLatitude()/Jt808Constant.ONE_MILLION));
    dsmAlarmInfo.setLng((float)(alarm.getLongitude()/Jt808Constant.ONE_MILLION));
    dsmAlarmInfo.setAlarmTime(alarm.getAlarmTime());

    dsmAlarmInfo.setFatigueDegree(alarm.getFatigueDegree());
    dsmAlarmInfo.setSpeed(alarm.getSpeed());
    dsmAlarmInfo.setReserves(alarm.getReserves());

    // 车辆状态
    dsmAlarmInfo.setVehicleStateBits(alarm.getStatusBit());

    // 报警标识
    AlarmIdentificationInfo alarmIdentificationInfo = new AlarmIdentificationInfo();
    dsmAlarmInfo.setAlarmIdentification(alarmIdentificationInfo);
    alarmIdentificationInfo.setDeviceId(alarm.getDeviceId());
    alarmIdentificationInfo.setTime(alarm.getDateTime());
    alarmIdentificationInfo.setSequenceNo(alarm.getSequenceNo());
    alarmIdentificationInfo.setAttachmentNum(alarm.getAttachmentNum());
    return dsmAlarmInfo;
  }
}
